# 围棋事件处理
class GoEvent(object):

    def __init__(self, goRuleManager):
        self.goRuleManager = goRuleManager

    # 处理鼠标点击事件
    def mouseButtonOnDownEvent(self, event, font, gameOver, height, width):
        x1, y1 = event.pos
        print("点击位置：" + str(x1)+","+str(y1))
        if event.button == 1:  # 按下的是鼠标左键

            if x1 < 685 and y1 < 685:
                i, j = self.goRuleManager.get_coord(event.pos)  # 将物理坐标转换成矩阵的逻辑坐标
                if self.goRuleManager.check_at(i, j):  # 检查(i,j)位置能否被占用，如未被占用返回True
                    # 在(i,j)位置落子，该函数将黑子或者白子画在棋盘上
                    self.goRuleManager.handleRuleDropAt(i, j)
                else:
                    print('此位置已占用，不能在此落子')
            else:
                self.clickButton(event, font, gameOver, x1, y1)
        return gameOver

    def clickButton(self, event, font, gameOver, x, y):
        if self.goRuleManager.start_again.rect.collidepoint(x, y):
            self.goRuleManager.startAgain()
        if self.goRuleManager.kuso1_button.rect.collidepoint(x, y):
            self.goRuleManager.kuso1()

